package com.example.service;

import com.example.config.RabbitMQFanoutConfig;
import com.example.pojo.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 胡成
 * @Version: 0.0.1V
 * @Date: 2018/12/7
 * @Description: 类描述
 **/
@Slf4j
@Service
public class ReceiverFanoutService {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendFanout(){
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId("10000");
        userDTO.setName("zhangsan");

        log.info("【sendFanout已发送消息】");
        //注意，这里到第二个参数为空
        //因为fanout交换器不处理路由键，只是简单的将队列绑定到交换器上
        //每个发送到交换器上到消息都会被转发到与该交换器绑定到所有队列上
        amqpTemplate.convertAndSend(RabbitMQFanoutConfig.FANOUT_EXCHANGE,"",userDTO);
    }
}
